package com.hdoit.ares.web.home.apis;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tennetcn.common.logical.app.model.LoginAuthority;
import com.tennetcn.component.webapi.ResponseModel;
import com.tennetcn.component.webapi.ResponseStatus;

@Controller
@RequestMapping(value = "/api/v1/authorityAres/",method = { RequestMethod.GET,RequestMethod.POST},produces="application/json;charset=utf-8")
@Api(value = "/api/v1/authorityAres/")
@CrossOrigin(origins = "*",maxAge = 3600)
public class AuthorityAresApi extends HomeAresApi{
	
	private final String isSignApi="isSign";
	
	private final String getSignApi="getSign";
	
	@ResponseBody
	@RequestMapping(value = isSignApi)
	@ApiOperation(notes = isSignApi, httpMethod = "POST", value = "判断sign是否合法")
	public String isSign(){
		ResponseModel rm=new ResponseModel();
		rm.setStatus(ResponseStatus.success);
		rm.setMessage("ok");
		LoginAuthority loginAuthority=loginAuthorityService.queryModelBySign(getSignCode());
		rm.put("result", loginAuthority!=null);
		
		return rm.toJson();
	}
	
	@ResponseBody
	@RequestMapping(value = getSignApi)
	@ApiOperation(notes = getSignApi, httpMethod = "POST", value = "获取sign信息")
	public String getSign(){
		ResponseModel rm=new ResponseModel();
		rm.setStatus(ResponseStatus.success);
		rm.setMessage("ok");
		LoginAuthority loginAuthority=loginAuthorityService.queryModelBySign(getSignCode());
		rm.putObj("sign", loginAuthority,"loginId","loginName","signCode","expireDate");
		
		return rm.toJson();
	}
}
